import Taro from '@tarojs/taro'
import { observable, action } from 'mobx'

export default class IndexStore {
  @observable scanUrl: string = ''

  @action
  scanCode () {
    Taro.scanCode()
      .then(res => {
        const result = JSON.parse(res.result)
        this.scanUrl = result.url
        switch (result.type) {
          case 1:
            Taro.navigateTo({ url: '/pages/input/index' })
            break
          case 2:
            Taro.navigateTo({ url: '/pages/tool-detail/index' })
            break
          default:
            break
        }
      })
      .catch(e => {
          console.log(e)
      })
  }
}
